package StudentMS;

import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        System.out.println("-----------------欢迎来到学生管理系统-----------------");

        loop:while(true) {
            System.out.println("请选择你的操作:");
            System.out.println("1.添加学生");
            System.out.println("2.删除学生");
            System.out.println("3.修改学生");
            System.out.println("4.查询学生");
            System.out.println("5.退出");

            Scanner sc = new Scanner(System.in);
            int choice = sc.nextInt();
            switch (choice) {
                case "1" -> AddStudent(list);
                case "2" -> DelStudent();
                case "3" -> UpdateStudent();
                case "4" -> QueryStudent();
                case "5" -> {
                    System.out.println("退出");
                    break loop;
                }
            }
        }


    }

    //添加学生(id不可重复)
    public static void AddStudent(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        while(true){
            System.out.println("请输入要添加的学生id");
            String id = sc.next();
            //判断id是否重合
            contains(id,list);
            if(!contains(id,list)){
                System.out.println("id有重复,请重新输入");
            }else{
                break;
            }
        }
        System.out.println("请输入要添加的学生姓名");
        String name = sc.next();
        System.out.println("请输入要添加的学生年龄");
        int age = sc.nextInt();
        System.out.println("请输入要添加的学生家庭地址");
        String address = sc.next();

    }

    public static int getIndex(){}

    //判断id是否重合
    public static boolean contains(String id,ArrayList<Student> list){
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            String sid = s.getId();
            boolean result = s.equals(id);
            if(!result){
                //id不重合,可以继续
                return true;
            }
        }
        //id重合,不可以继续
        return false;
    }
    /*AddStudent();
    DelStudent();
    UpdateStudent();
    QueryStudent();*/
}
